<script setup>
import { HomeFilled, User, Avatar } from '@element-plus/icons-vue'
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/stores'

const userStore = useUserStore()
const route = useRoute()
const router = useRouter()

const activeMenu = computed(() => route.path)

const currentPath = computed(() => {
  const pathMap = {
    '/admin/home': '首页',
    '/admin/student-management': '学生管理',
    '/admin/teacher-management': '老师管理',
  }
  return pathMap[route.path] || '未知页面'
})

// 退出登录处理
const handleCommand = (command) => {
  if (command === 'logout') {
    userStore.reset()
    ElMessage.success('已退出登录')
    router.push('/login')
  }
}
</script>
<template>
  <el-container style="height: 100vh;">
    <el-aside width="200px" style=" border-right: 1px solid #e9ecef;">
      <div class="logo-container">
        <h2>管理端</h2>
      </div>
      <el-menu router :default-active="activeMenu" class="menu" background-color="#f0f2f5" text-color="#333"
        active-text-color="#fff">
        <el-menu-item index="/admin/home">
          <el-icon>
            <HomeFilled />
          </el-icon>
          <span>首页</span>
        </el-menu-item>
        <el-menu-item index="/admin/student-management">
          <el-icon>
            <User />
          </el-icon>
          <span>学生管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/teacher-management">
          <el-icon>
            <Avatar />
          </el-icon>
          <span>教师管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="border-bottom: 1px solid #e9ecef;">
        <div class="header-container">
          <div class="header-left">
            <el-breadcrumb separator="/">
              <el-breadcrumb-item :to="{ path: '/admin/home' }">管理端</el-breadcrumb-item>
              <el-breadcrumb-item>{{ currentPath }}</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div class="header-right">
            <el-dropdown @command="handleCommand">
              <span class="user-info">
                <el-avatar :size="32" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
                <span style="margin-left: 8px;">1</span>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item divided command="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>


<style scoped>
/* 主容器样式 */
.el-container {
  background-color: linear-gradient(135deg, #a8c9ff, #d1e7ff) !important;
  /* background-color: #303133; */
}

/* 左侧菜单样式优化 */
.el-aside {
  background: linear-gradient(135deg, #a8c9ff, #d1e7ff) !important;
  box-shadow: 1px 0 10px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.el-aside:hover {
  box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
}

.logo-container {
  padding: 20px;
  text-align: center;
  /* background: linear-gradient(135deg, #409eff 0%, #66b1ff 100%); */
  box-shadow: 0 2px 10px rgba(64, 158, 255, 0.2);
  margin-bottom: 1px;
  position: relative;
  overflow: hidden;
}
.logo-container h2 {
  margin: 0;
  color: #303133;
  font-size: 20px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 菜单项样式优化 */
.el-menu {
  font-size: 14px;
  border-right: none;
}

.el-menu-item {
  height: 48px;
  line-height: 48px;
  transition: all 0.2s ease;
  padding-left: 30px;
  position: relative;
}

.el-menu-item:hover {
  background-color: #e6f7ff;
}

.el-menu-item i {
  color: #66b1ff;
  width: 20px;
  text-align: center;
  margin-right: 10px;
}

.el-menu-item span {
  color: #606266;
  transition: color 0.2s ease;
}

.el-menu-item.is-active {
  background-color: #399cff8c;
  box-shadow: inset 3px 0 0 #3a8de693;
}

.el-menu-item.is-active i {
  color: #fff;
}

.el-menu-item.is-active span {
  color: #fff;
}

.el-menu-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background-color: transparent;
  transition: all 0.3s ease;
}

.el-menu-item:hover::before,
.el-menu-item.is-active::before {
  background-color: #409eff;
}

/* 头部样式优化 */
.el-header {
  background-color: #fff;
  padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  background: linear-gradient(135deg, #a8c9ff, #d1e7ff);
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

.header-left {
  font-size: 16px;
  font-weight: 500;
  color: #303133;
}

.header-right .user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.header-right .el-avatar {
  margin-right: 8px;
  transition: all 0.3s ease;
}

.header-right .user-info:hover .el-avatar {
  transform: scale(1.05);
}

/* 面包屑样式优化 */
.el-breadcrumb {
  font-size: 14px;
  color: #606266;
}

.el-breadcrumb__item:last-child {
  color: #909399;
}

/* Dropdown 菜单优化 */
.el-dropdown-menu {
  min-width: 150px;
  border-radius: 4px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.el-dropdown-item {
  padding: 10px 20px;
  font-size: 14px;
  transition: all 0.2s ease;
}

.el-dropdown-item:hover {
  background-color: #e6f7ff;
  color: #409eff;
}

/* 内容区域优化 */
.el-main {
  padding: 20px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  background: linear-gradient(135deg, #a8c9ff, #d1e7ff);
}
</style>
